//
//  WXPAutoFirstBorrowPopUpView.m
//  自动首借提示弹窗
//
//  Created by wxp on 2025/3/3.
//

#import "WXPAutoFirstBorrowPopUpView.h"

@implementation WXPAutoFirstBorrowPopUpView

#pragma mark - lazy
- (UIImageView *)imaegTop{
    if (_imaegTop == nil) {
        _imaegTop = [UIImageView new];
        _imaegTop.image = [UIImage imageNamed:@"icon-auto-first-borrow-top"];
        _imaegTop.widthHeight = XY(Ratio(224), Ratio(210));
    }
    return _imaegTop;
}
- (UIView *)viewBack{
    if (_viewBack == nil) {
        _viewBack = [UIView new];
        _viewBack.backgroundColor = COLOR_WHITE;
        _viewBack.width = SCREEN_WIDTH-2*LEFT_MARDIN;
        [GlobalMethod setRoundView:_viewBack color:[UIColor clearColor] numRound:16 width:0];
    }
    return _viewBack;
}
- (UILabel *)labelTitle{
    if (_labelTitle == nil) {
        _labelTitle = [UILabel new];
        _labelTitle.textColor = COLOR_BLACK;
        _labelTitle.fontNum = 18;
        [_labelTitle fitTitle:@"Enhorabuena" variable:0];
    }
    return _labelTitle;
}
- (UILabel *)labelContent{
    if (_labelContent == nil) {
        _labelContent = [UILabel new];
        _labelContent.textColor = COLOR_CONTENT;
        _labelContent.fontNum = 12;
        _labelContent.numberOfLines = 0;
        _labelContent.lineSpace = 5;
        _labelContent.textAlignment = NSTextAlignmentCenter;
        [_labelContent fitTitle:@"Ha completado los pasos más claves de verificación!\n¡Un préstamo será generado para usted\ninmediatamente!" variable:0];
    }
    return _labelContent;
}
- (UILabel *)labelMoney{
    if (_labelMoney == nil) {
        _labelMoney = [UILabel new];
        _labelMoney.textColor = COLOR_BLACK;
        _labelMoney.font = [UIFont boldSystemFontOfSize:18];
        [_labelMoney setAttributedText:[@"¡Hasta 3500!" setDifferentColorWithMarkStr:@"3500!" lineSpacing:0 alignment:NSTextAlignmentCenter color:[UIColor colorWithHexString:@"#EFB006"]]];
        [_labelMoney sizeToFit];
    }
    return _labelMoney;
}
-(UIButton *)btnConfirm{
    if (_btnConfirm == nil) {
        _btnConfirm = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnConfirm.widthHeight = XY(self.viewBack.width-30-30, BUTTON_HEIGHT);
        _btnConfirm.backgroundColor = COLOR_PRIMARY;
        _btnConfirm.titleLabel.font = [UIFont systemFontOfSize:14];
        [GlobalMethod setRoundView:_btnConfirm color:[UIColor clearColor] numRound:BUTTON_HEIGHT/2 width:0];
        [_btnConfirm setTitle:@"Entiendo" forState:(UIControlStateNormal)];
        [_btnConfirm setTitleColor:COLOR_BLACK forState:UIControlStateNormal];
        WEAKSELF
        [_btnConfirm setNoRepeatActionWithInterval:1 action:^(UIButton * _Nonnull button) {
            [NSObject clickFeedback];
            [weakSelf.btnConfirm addClickAnimate];
            [weakSelf removeFromSuperview];
        }];
    }
    return _btnConfirm;
}

#pragma mark 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.widthHeight = XY(SCREEN_WIDTH, SCREEN_HEIGHT);
        self.userInteractionEnabled = true;
        self.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.4];
        [self addSubView];
    }
    return self;
}
//添加subview
- (void)addSubView{
    [self addSubview:self.imaegTop];
    [self addSubview:self.viewBack];
    [self.viewBack addSubview:self.labelTitle];
    [self.viewBack addSubview:self.labelContent];
    [self.viewBack addSubview:self.labelMoney];
    [self.viewBack addSubview:self.btnConfirm];
    [self resetView];
}

#pragma mark 刷新view
- (void)resetView{
    self.labelTitle.centerXTop = XY(self.viewBack.width/2, Ratio(35));
    
    self.labelContent.centerXTop = XY(self.labelTitle.centerX, self.labelTitle.bottom+Ratio(20));
    
    self.labelMoney.centerXTop = XY(self.labelTitle.centerX, self.labelContent.bottom+Ratio(18));
    
    self.btnConfirm.centerXTop = XY(self.labelTitle.centerX, self.labelMoney.bottom+Ratio(26));
    
    self.viewBack.height = self.btnConfirm.bottom+self.labelTitle.top;
    self.viewBack.centerXCenterY = XY(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
    self.imaegTop.centerXTop = XY(self.width/2, self.viewBack.top-Ratio(114));
}


@end
